/**
 * Created by zhouli on 18/9/4
 * Email li.zhou@huilianyi.com
 */
import config from 'config';
import httpFetch from 'share/httpFetch';
import errorMessage from 'share/errorMessage';
import EFService from 'containers/enterprise-manage/extend-field/extend-field.service';

export default {
  //获取表单类型
  getWidgetList(params) {
    // let params = {
    //   type:1003
    // }
    return new Promise((resolve, reject) => {
      httpFetch.get(config.baseUrl + '/api/form/gui/widgets/all', params)
        .then((res) => {
          resolve(res)
        })
        .catch((err) => {
          errorMessage(err.response);
          reject(err);
        })
    })
  },
  //获取扩展字段表单：部门扩展字段
  getCustomForm() {
    let params = {
      formCode:"department_attach_form "
    }
    return new Promise((resolve, reject) => {
      httpFetch.get(config.baseUrl + '/api/custom/forms/by/form/code',params)
        .then((res) => {
          resolve(res)
        })
        .catch((err) => {
          errorMessage(err.response);
          reject(err);
        })
    })
  },
  //创建部门信息扩展字段表单
  createCustomForm: function (form) {
    return new Promise((resolve, reject) => {
      httpFetch.post(config.baseUrl + '/api/users/v2/custom/forms', form)
        .then((res) => {
          resolve(res)
        })
        .catch((err) => {
          errorMessage(err.response);
          reject(err);
        })
    })
  },
  //保存表单
  updateCustomForm(form) {
    return new Promise((resolve, reject) => {
      EFService.updateCustomForm(form)
        .then((res) => {
          resolve(res)
        })
        .catch((err) => {
          reject(err);
        })
    })
  }

}
